package com.weixin.pay.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class ConfigUtil {
	
	
	/**
	 * 服务号相关信息
	 */
	 public final static String APPID = "";//服务号的应用号
	 public final static String APP_SECRECT = "";//服务号的应用密码
	 public final static String TOKEN = "";//服务号的配置token
	 public final static String MCH_ID = "";//商户号
	 public final static String API_KEY = "";//API密钥
	 
	 
	 public final static String SIGN_TYPE = "MD5";//签名加密方式
	// public final static String CERT_PATH = "D:/weixin/apiclient_cert.p12";//微信支付证书存放路径地址
	 
	//微信支付统一接口的回调action
	 public final static String NOTIFY_URL = "http://119.29.166.150/pay/weixinpay/payreturn";
	//微信支付成功支付后跳转的地址
	 public final static String SUCCESS_URL = "http://119.29.166.150/pay/weixinpay/paysuccess";
	 //oauth2授权时回调action
	 public final static String REDIRECT_URI = "http://119.29.166.150/pay/weixinpay/oauth2return";
	
	 /**
	 * 微信基础接口地址
	 */
	 //获取token接口(GET)
	 public final static String TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
	 //oauth2授权接口(GET)
	 public final static String OAUTH2_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
	 //刷新access_token接口（GET）
	 public final static String REFRESH_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN";
	// 菜单创建接口（POST）
	 public final static String MENU_CREATE_URL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
	// 菜单查询（GET）
	 public final static String MENU_GET_URL = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN";
	// 菜单删除（GET）
	public final static String MENU_DELETE_URL = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN";
	/**
	 * 微信支付接口地址
	 */
	//微信支付统一接口(POST)
	public final static String UNIFIED_ORDER_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder";
	//微信退款接口(POST)
	public final static String REFUND_URL = "https://api.mch.weixin.qq.com/secapi/pay/refund";
	//订单查询接口(POST)
	public final static String CHECK_ORDER_URL = "https://api.mch.weixin.qq.com/pay/orderquery";
	//关闭订单接口(POST)
	public final static String CLOSE_ORDER_URL = "https://api.mch.weixin.qq.com/pay/closeorder";
	//退款查询接口(POST)
	public final static String CHECK_REFUND_URL = "https://api.mch.weixin.qq.com/pay/refundquery";
	//对账单接口(POST)
	public final static String DOWNLOAD_BILL_URL = "https://api.mch.weixin.qq.com/pay/downloadbill";
	//短链接转换接口(POST)
	public final static String SHORT_URL = "https://api.mch.weixin.qq.com/tools/shorturl";
	//接口调用上报接口(POST)
	public final static String REPORT_URL = "https://api.mch.weixin.qq.com/payitil/report";
	
	
	private static final String WEIXIN_PROPERTY="/weixin.properties";
	private static Properties props = new Properties();

	static {
		try {
//			String basePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
//			File file = new File(basePath);
//			String parent = file.getParent();
//			String path = parent+File.separator+WEIXIN_PROPERTY;
			//props.load(path);
			//play框架下要用这种方式加载
			props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(WEIXIN_PROPERTY));
			//props.load(ConfKit.class.getResourceAsStream("/wechat.properties"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String get(String key) {
		return props.getProperty(key);
	}

    public static void setProps(Properties p){
        props = p;
    }
}
